package com.derbysoft.dswitch.adapter.ihg.common.domain.interceptor;

import com.derbysoft.dswitch.adapter.ihg.common.repository.TransactionLogRepository;
import com.derbysoft.dswitch.adapter.ihg.common.utils.DateTimeUtils;
import org.hibernate.EmptyInterceptor;

import java.util.Date;

public class CustomerHibernateLogShardsInterceptor extends EmptyInterceptor {

    private Date date;

    public CustomerHibernateLogShardsInterceptor(Date date) {
        this.date = date;
    }

    public String onPrepareStatement(String sql) {
        return sql.replace(TransactionLogRepository.TRANSACTION_TABLE,
                TransactionLogRepository.TRANSACTION_TABLE + TransactionLogRepository.UNDER_LINE + DateTimeUtils.formatDate(date, "yyyyMMdd"));
    }
}
